package com.haohan.jingyuan.config;

import com.haohan.jingyuan.gateway.filter.GatewayFilter;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * 过滤器配置类
 *
 * @ClassName FilterConfig
 * @Description 配置过滤器的执行顺序
 * @Author hexijun
 * @Time 2025/01/19 12:00
 * @Version 1.0
 */
@Configuration
@RequiredArgsConstructor
public class FilterConfig {

    private final GatewayFilter gatewayFilter;

    /**
     * 统一网关过滤器注册
     */
    @Bean
    public FilterRegistrationBean<GatewayFilter> gatewayFilterRegistration() {
        FilterRegistrationBean<GatewayFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(gatewayFilter);
        registration.addUrlPatterns("/*");
        registration.setName("gatewayFilter");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
}
